<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    #baner{
      width: 1000px;
      margin: 0 auto;
      position: relative;
    }
    #img{
      width: 1000px;
      height: 600px;
    }
    #ul{
      list-style: none;
      position: absolute;
      bottom: 15px;
      left:45%;
    }
    #ul>li{
      float: left;
      width: 10px;
      height: 10px;
      border-radius: 50%;
      background-color:red;
      margin: 5px;
    }
    #left{
      position: absolute;
      left:5px;
      top:45%;
    }
    #right{
      position: absolute;
      right:5px;
      top:45%;
    }
    .active{
      background-color:white !important;
    }
  </style>
</head>
<body>
  <div id="baner">
    <span id="left"><img src="./images/img/xiaoyuhao.png" alt=""></span>
    <img id="img" src="https://i1.mifile.cn/a4/xmad_15535933141925_ulkYv.jpg" alt="">
    <span id="right"><img src="./images/img/dayuhao.png" alt=""></span>
    <ul id="ul">
      <li class="active"></li>
      <li></li>
      <li></li>
    </ul>
  </div>
    
  <script>
    var baner=document.getElementById("baner");
    var img=document.getElementById("img");
    var left=document.getElementById("left");
    var right=document.getElementById("right");
    var lis=document.getElementsByTagName("li");
    var n=0;
    var timer="null";

    arry=[
        "https://i1.mifile.cn/a4/xmad_15535933141925_ulkYv.jpg",
        "https://i1.mifile.cn/a4/xmad_15532384207972_iJXSx.jpg",
        "https://i1.mifile.cn/a4/xmad_15517939170939_oiXCK.jpg",
      ];
    
    function autoplay(){
    timer=setInterval(function(){
      n++;
     if(n==arry.length){
       n=0
     }
     changeImg();
     console.log(n)
     },2000)
    }
    setTimeout(autoplay,1000);

    function changeImg(){
      img.src=arry[n];
      for(i=0;i<lis.length;i++){
        lis[i].className="";
       }
       lis[n].className="active";
    };

    for(i=0;i<arry.length;i++){
      lis[i].index=i;
      lis[i].onclick=function(ev){
        n=this.index;
        changeImg();
        console.log(n);
      }
    }

  left.onclick=function(ev){
        n--;
      if(n==-1){
       n=arry.length-1;
 }
    changeImg();
    console.log(n);
}

right.onclick = function(ev){
 n++;
 if(n==arry.length){
     n=0;
 }
 changeImg();
 console.log(n);
}

baner.onmouseover=function(){
  clearInterval(timer);
}
baner.onmouseout=autoplay;
   console.log(arry.length)
  </script>
</body>
</html>